package com.neo.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.HashKit;

public class loginInterceptor implements Interceptor {

    private static final String SESSION_VlUES = "LI_YANG_NEO";

    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        String userName = controller.getSessionAttr("userName");

        // 用户如果没有登录，那么就跳转到登录页面
        if (userName == null) {
            controller.setAttr("statusCode", 200);
            controller.setAttr("message", "请先登陆");
            //没有登陆则返回登陆页,提示需要登陆
            System.out.println("该用户没有登陆");
            controller.renderFreeMarker("/halo/login.html");

        } else {
            inv.invoke();
        }

    }
}
